//
//  FBtExten.m
//  JwPack
//
//  Created by 陈警卫 on 2025/7/29.
//

#import "FBtExten.h"

@implementation FBtExten

@end

@implementation NSData (FBtExten)

/// data转16进制字符串
- (NSString *)f_hexString {
    if (self.length <= 0) {
        return @"";
    }
    Byte *bytes = (Byte *)[self bytes];
    NSMutableString *hexString = [[NSMutableString alloc] init];
    NSUInteger length = [self length];
    for (NSUInteger i = 0; i < length; i++) {
        [hexString appendFormat:@"%02X", bytes[i]];
    }
    return hexString;
}

@end

@implementation NSDate (FBtExten)

/// 报文ID
+ (NSData *)f_packetIDData {
    static UInt16 counter = 0;
    UInt32 ts = (UInt32)[[NSDate date] timeIntervalSince1970];
    UInt32 packetID = (ts << 16) | (counter++ & 0xFFFF);
    UInt32 bigEndianID = htonl(packetID);
    return [NSData dataWithBytes:&bigEndianID length:4];
}


@end
